package com.ericsson.resourceplanner.utils;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.springframework.stereotype.Component;

import com.ericsson.resourceplanner.login.landingpage.Landingpage;
import com.ericsson.resourceplanner.login.landingpage.Landingpages;

public class ReadLandingPageUtil {

	public Map<String, String> getLandingPageName()
	{
		//File f = new File("LandingPage.xml"); 
		ClassLoader classLoader = getClass().getClassLoader();
		File f = new File(classLoader.getResource("LandingPage.xml").getFile());
		
		//System.out.println("File if exists-----------"+f.exists());
		Landingpages landingpages = null;

		try
		{
			JAXBContext jAXBContext = JAXBContext.newInstance(Landingpages.class);
			Unmarshaller unmarshaller = jAXBContext.createUnmarshaller();
			landingpages = (Landingpages)unmarshaller.unmarshal(f);				
		}
		catch(JAXBException je)
		{
			je.printStackTrace();
		}
	
		Map<String, String> map = new HashMap<String, String>();
		for(Landingpage lp : landingpages.getLandingpage())
		{
			map.put(lp.getRole(), lp.getHomepage());
		}
		return map;
	}
}
